A Package can be defined as a grouping of related types (classes, interfaces, enumerations and annotations ) providing access protection and namespace management.
Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc.
Import a package;
If a class wants to use another class in the same package, the package name need not be used. Classes in the same package find each other without any special syntax.
All java methods must be contained in a class, and all program statements must be placed inside a method.
public: Public means a class or method is usable outside of the class, whereas private data members or methods.
Static: Static means that the variable or method marked as such is avaliable at the class level. In other words, you don't need to create a instatance of the class to access it.
Void: Void means the reaturn value of this is Null.
Identifiers
Identifiers are the names of variables, methods, classes, packages and interfaces. Unlike literals they are not the things themselves, just ways of referring to them. In the HelloWorld program, HelloWorld, String, args, main and println are identifiers.
Identifiers must be composed of letters, numbers, the underscore _ and the dollar sign $. Identifiers may only begin with a letter, the underscore or a dollar sign.
Over flow error: try to store a value whose magnitude is too big in a variable.
A varuable is often initialized in its declarations
Storage of numbers Hexadecimal and Octal Numbers
Decimal Number System: Decimal number system has ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, called digits. It uses positional notation. That is, the least-significant digit (right-most digit) is of the order of 10^0 (units or ones), the second right-most digit is of the order of 10^1(tens), the third right-most digit is of the order of 10^2 (hundreds), and so on.
Binary Number System: Binary number system has two symbols: 0 and 1, called bits. It is also a positional notation. binary digit is called a bit. Eight bits is called a byte.
Hexadecimal number system uses 16 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F, called hex digits. Each hexadecimal digit is also called a hex digit. Most programming languages accept lowercase 'a' to 'f' as well as uppercase 'A' to 'F'.Computers uses binary system in their internal operations, as they are built from binary digital electronic components. However, writing or reading a long sequence of binary bits is cumbersome and error-prone. Hexadecimal system is used as a compact form or shorthand for binary bits. Each hex digit is equivalent to 4 binary bits
A link about how to store a negative number in computer:
Operators Arithmetic Operators:
- Subtraction operator
* Multiplication operator
/ Division operator
% Remainder operator
Relational Operators:
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
Logical Operators:
&& Conditional-AND
|| Conditional-OR
! Conditional-NOT
Assignment Operators:
publicclass Test {publicstaticvoid main(String args[]){int a =10;int b =20;int c =0;
c = a + b;System.out.println("c = a + b = "+ c );
c += a ;System.out.println("c += a = "+ c );
c -= a ;System.out.println("c -= a = "+ c );
c *= a ;System.out.println("c *= a = "+ c );
a =10;
c =15;
c /= a ;System.out.println("c /= a = "+ c );
a =10;
c =15;
c %= a ;System.out.println("c %= a = "+ c );
c <<=2;System.out.println("c <<= 2 = "+ c );
c >>=2;System.out.println("c >>= 2 = "+ c );
c >>=2;System.out.println("c >>= 2 = "+ c );
c &= a ;System.out.println("c &= a = "+ c );
c ^= a ;System.out.println("c ^= a = "+ c );
c |= a ;System.out.println("c |= a = "+ c );}}
Output:
c = a + b =30
c += a =40
c -= a =30
c *= a =300
c /= a =1
c %= a =5
c <<=2=20
c >>=2=5
c >>=2=1
c &= a =0
c ^= a =10
c |= a =10
AP Computer Science A : Chapter 1
Packges and Classes
Identifiers
Storage of numbers
Hexadecimal and Octal Numbers
Operators
Arithmetic Operators:
- - Subtraction operator
- * Multiplication operator
- / Division operator
- % Remainder operator
Relational Operators:- == Equal to
- != Not equal to
- > Greater than
- >= Greater than or equal to
- < Less than
- <= Less than or equal to
Logical Operators:- && Conditional-AND
- || Conditional-OR
- ! Conditional-NOT
Assignment Operators:Output:
Increment and Decrement Operators:
(´・_・`) Have a good day~